package cn.weisoft.nconv.mapper;

import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

public class GardenDynamicSqlProvider {
    public String selectWithParam(Map<String, Object> param) {

       /* String sql = new SQL(){
            SELECT("*");
            FROM("garden");
            if(param.get("title")!=null && param.get("title")!=""){
                WHERE("title like #{title}");
            }
            WHERE("");
        }.toString();
        sql += getWhere(param);
*/
       String sql = " select * from ( select * from garden where 1=1 ";
        if(param.get("title")!=null && param.get("title")!="") {
            sql += " and title like #{title} ";
        }
        sql += " ) as temp limit #{currentIndex} ,#{pageSize} ";

        return sql;
    }

    public String countWithPara(Map<String, Object> param) {
        String sql = " select count(1) from garden   where 1=1  ";
        if(param.get("title")!=null && param.get("title")!="") {
            sql += " and title like #{title} ";
        }

        return sql;
    }

    /*private String getWhere(Map<String, Object> para) {
        String sql = new SQL(){

            if(para.get("title")!=null && para.get("title")!=""){
                WHERE("title like #{title}");
            }


        }.toString();

        return sql;
    }*/
}

